#pragma once
#include "EXScrollBarThumb.h"
#include "EXScrollBarResSet.h"
// CEXScrollBar
#define WM_DEF_MOUSEWHEEL (WM_USER+1)

class AFX_EXT_CLASS CEXScrollBar : public CWnd
{
	friend class CEXListCtrlWnd;
	friend class CEXScrollBarThumb;

	DECLARE_DYNAMIC(CEXScrollBar)

public:
  enum SCROLL_STYLE
  {
    NOIMAGE,
    SCROLLBAR_CTRL = 16,
  };

	CEXScrollBar();
	virtual ~CEXScrollBar();

	virtual BOOL Create(DWORD dwStyle, const RECT& rect, 
                      CWnd* pParentWnd, UINT nID);

	int GetScrollPos() const;
	int SetScrollPos(int nPos, BOOL bRedraw = TRUE);
 	void GetScrollRange(LPINT lpMinPos, LPINT lpMaxPos) const;
 	void SetScrollRange(int nMinPos, int nMaxPos, BOOL bRedraw = TRUE);

	BOOL SetScrollInfo(LPSCROLLINFO lpScrollInfo, BOOL bRedraw = TRUE);
	BOOL GetScrollInfo(LPSCROLLINFO lpScrollInfo, UINT nMask = SIF_ALL);
	int GetScrollLimit();

	int SetArrowSize(int nSize);

	BOOL SetLeftUpButtonBitmap(UINT nID, int nCount);
	BOOL SetRightDownButtonBitmap(UINT nID, int nPics);
	BOOL SetPageButtonBitmap(UINT nID, int nPics);
	BOOL SetThumbBitmap(UINT nThumbID, UINT nBkgndID, UINT nIconID, int nPics,
		                  int nLeftWidth = 0, int nRightWidth = 0, 
                      int nTopHeight = 0, int nBottomHeight = 0);

	void SetListErase(BOOL bErase);

  void SetResSet(CEXBaseResSet* pResSet);
  CEXScrollBarResSet* m_pScrollResSet;

protected:
	void LimitThumbPosition(CRect & rcClient);
	void CalcScroll(CRect & rcClient, BOOL bResize = FALSE);
	void SetPositionFromThumb();
	void UpdateThumbPosition(CRect & rcClient);
	void DrawScroll(CDC * pDC);
	void FreeTimer();
	void SetThumbPosition(CRect & rcThumb,  BOOL bContinued);

	BOOL InitBgBitmap( CBitmap & bmpSrc, CBitmap & bmpDest, int nIndex, 
                    int nCount, BOOL bResize = TRUE);

protected:
	enum STATUS
	{
		normal,
		focus,
		select,
		disable
	};

	int     m_nMin;
	int     m_nMax;
	UINT    m_nPage;
	int     m_nPos;
	int     m_nTrackPos;
	BOOL    m_bHorizontal;
	int		m_nPrevMax;
	BOOL	m_bClick;
	BOOL	m_bContinued;
	int		m_nArrowSize;
	CSize	m_siThumb;

	CRect   m_rcLeftUpArrow;
	CRect   m_rcRightDownArrow;
	CRect   m_rcScroll;
	CRect	m_rcScrollLeftUp;
	CRect	m_rcScrollRightDown;
	CRect   m_rcThumb;

	UINT	m_nLeftUpTimerID;
	UINT	m_nRightDownTimerID;
	UINT	m_nPageLeftUpTimerID;
	UINT	m_nPageRightDownTimerID;

	CPoint	m_ptPrevPos;

	CEXScrollBarThumb m_wndThumb;

	UINT m_nLeftUpBitmapID;
	int m_nLeftUpPic;
	BOOL m_bSetLeftUpBitmap;
	CBitmap m_bmpLeftUp;

	UINT m_nRightDownBitmapID;
	int m_nRightDownPic;
	BOOL m_bSetRightDownBitmap;
	CBitmap m_bmpRightDown;

	UINT m_nPageBitmapID;
	int m_nPagePic;
	BOOL m_bSetPageBitmap;
	CBitmap m_bmpPageNormal;
	CBitmap m_bmpPageSelect;
	CBitmap m_bmpPageFocus;
	CBitmap m_bmpPageDisable;

	SKIN_STATUS m_LeftUpSkin;
	SKIN_STATUS m_RightDownSkin;

	UINT m_uLeftUpTimer;
	UINT m_uRightDownTimer;

protected:
	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnPaint();
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	afx_msg void OnDestroy();
	afx_msg LRESULT OnMouseWheelNotify(WPARAM w, LPARAM l);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
};
